package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 13:01 2020/3/29
 * @Description  二叉树的深度
 */

public class LeetCode_FaceTest55_I {


    // 能进入就说明了这个节点是存在的，每层都根据最底层的左右子树的最大层+1
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        int maxDepthLeft = 0;
        int maxDepthRight = 0;
        if (root.left != null) {
            maxDepthLeft = maxDepth(root.left);
        }
        if (root.right != null) {
            maxDepthRight = maxDepth(root.right);
        }
        return Math.max(maxDepthLeft, maxDepthRight)+1;
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}
